package com.dragon.test.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAcpect {

	@Pointcut(value = "execution(public int com.dragon.test.util.MathCaltulator.div(..))")
	public void pointCut() {
	}

	@Before(value = "pointCut()")
	public void onBefore() {
		System.out.println("计算开始：Before====");
	}

	@After(value = "pointCut()")
	public void onAfter() {
		System.out.println("计算结束：After====");
	}

	@AfterReturning(value = "pointCut()", returning = "result")
	public void onReturn(Integer result) {
		System.out.println("计算返回：Return====" + result);
	}

	@AfterThrowing(value = "pointCut()", throwing = "exception")
	public void onException(Exception exception) {
		System.out.println("计算出现异常：Exception====");
		System.out.println(exception);
	}

	@Around(value = "pointCut()")
	public Object onAround(ProceedingJoinPoint pjp) throws Throwable {
		Object result = null;
		System.out.println("计算之前：Around====");
		result = pjp.proceed(pjp.getArgs());
		System.out.println("计算之后：Around====");
		return result;
	}

}
